# -*- coding: utf-8 -*-
<%inherit file="/base_form.mako"/>

<%namespace name="room_comps" file="/rooms/components.mako"/>
<%namespace name="machine_comps" file="/machines/components.mako"/>
<%namespace name="gen_comps" file="/components.mako"/>

<%def name="javascript()">
    ${parent.javascript()}
    ${self.javascript_link('jquery', 'ping', 'student_detail',
                           'validation/editstudent')}
</%def>

<%def name="css()">
    ${parent.css()}
    ${self.css_link('studentdetail')}
</%def>

<%def name="authorization_box(student)">
  <%
    add_group_url = action=h.url_for(controller='students', id=student.id, 
                                     action='add_group')
    remove_group_url = action=h.url_for(controller='students', id=student.id, 
                                        action='remove_group')    
    value = {'object_id': student.id}                         
  %>
  <legend>Authorization</legend>
  %if not student.groups:
    No privileges
    ${self.form('add_group_form', dict(group='admin', submit='Make admin',
                                       object_id=student.id),
                action=add_group_url, 
                method='POST',
                )}
  %else:
    %if len(student.groups) == 1:
      Admin
      ${self.form('remove_group_form', dict(group='admin',
                                            submit='Unmake Admin',
                                            object_id=student.id),
                  action=remove_group_url,
                  method='POST',
                  )}
      ${self.form('add_group_form', dict(group='superadmin',
                                         submit='Make Super Admin',
                                         object_id=student.id),
                  action=add_group_url,
                  method='POST',
                  )}
    %else:
        Super Admin
        ${self.form('remove_group_form', dict(group='superadmin',
                                              submit='Unmake Super Admin',
                                              object_id=student.id),
                    action=remove_group_url,
                    method='POST',
                    )}
    %endif
  %endif 
</%def>

<%def name="rooms_section(student)">
  <h3>Rooms:</h3>
  <table>
    <tr>
      <th>From</th>
      <th>To</th>
      <th>Room</th>
    </tr>
  %for roomassoc in student.roomassociations:
    <tr>
        <td>
          ${roomassoc.from_date|h}
      </td>
      <td>
        ${roomassoc.to_date or u'Now'|h}
      </td>
      <td>
        ${room_comps.link_to(roomassoc.room)}
      </td>
    </tr>
  %endfor
  </table>
</%def>

<%def name="machines_section(student)">
  <h3>
  Machines:
  </h3>
  <ul>
    %for machine in student.machines:
      <li>
        ${machine_comps.link_to(machine)|h}, ${machine.ip or '-'|h}
        ${machine_comps.status(machine)}
      </li>
    %endfor
  </ul>
</%def>

<%def name="general_info(student)">
  
  <h1> ${student.firstname|h} ${student.lastname|h} 
      (${student.username|h})</h1>
      
  <div id="student_info_wrapper">
    <br />
    Email: 
    ${h.mail_to(student.nice_email, student.email, 
                cc='"Ciby-Net" <%s>' % g.cibynet_email,
                subject="[Ciby-Net]")}
                  
    <br />
    Phone: ${student.phonenumber or '-'} 
  </div>
    
  <div id="rooms_wrapper">
    ${self.rooms_section(student)}
  </div>
</%def>

<%def name="showstudent(student)">

  <div id="edit_authorization_wrapper">  
    <a id="student_edit_link" 
       href="${h.url_for('edit_student', id=student.id)}">Edit</a>
    ##${gen_comps.button_to_delete("student", student.id)}
    <br />
    <fieldset id="authorization_box">
      ${self.authorization_box(student)}
    </fieldset>
  </div>
  
  <div id="student_general_info_wrapper">
    ${self.general_info(student)}
  </div>
  
  <div id="student_machines_wrapper">
    ${machines_section(student)}
  </div>
  
</%def>

<%def name="body()">
  ${showstudent(c.student)}
</%def>
